import {mapMutations} from 'vuex'

export default {
    ...mapMutations([
		''
    ]),
	//
	delRelation(e){
		let that = this
		that.$toast.confirm({
			content: '确定删除？',
			callback: result => {
				if (result) {
					//关注
					if(this.current == 0){
						that.$httpRequest.get({
							that: that,
							url: 'h5/deleteFollow',
							params: {
								followUserId:e.data.followUserId
							},
							success: res => {
								if (res.code === that.$httpConfig.SUCCESS_CODE) {
									// that.list.forEach((item,index)=>{
									// 	if(item.followUserId ==e.data.followUserId) {
									// 		that.list.splice(index,1)
									// 	}
									// })
									that.initArray()
								} else {
									
								}
							}
						})
					}else{
						that.$httpRequest.get({
							that: that,
							url: 'h5/deleteFans',
							params: {
								userId:e.data.userId
							},
							success: res => {
								if (res.code === that.$httpConfig.SUCCESS_CODE) {
									// that.list.forEach((item,index)=>{
									// 	if(item.followUserId ==e.data.followUserId) {
									// 		that.list.splice(index,1)
									// 	}
									// })
									that.initArray()
								} else {
									
								}
							}
						})
					}
				}
			}
		})
		
		
	},
	toNotes(id,item){
		console.log(id,item)
		this.sumbitId = id
		if(this.current == 0){
			this.userName = item.userComment || item.userName
		}else{
			this.userName = item.followComment || item.userName
		}

		this.$refs.notesPopup.open()
	},
	notesSubmit(){
		let that = this
		this.userName = name
		//关注
		if(this.current == 0){
			that.$httpRequest.request({
				that: that,
				url: 'h5/editFollowComment',
				params: {
					followUserId:that.sumbitId,
					userComment:that.notes
				},
				success: res => {
					if (res.code === that.$httpConfig.SUCCESS_CODE) {
						that.close()
						that.notes = null
						that.initArray()
					} else {
						
					}
				}
			})
		}else{
			that.$httpRequest.request({
				that: that,
				url: 'h5/editFansComment',
				params: {
					userId:that.sumbitId,
					followComment:that.notes
				},
				success: res => {
					if (res.code === that.$httpConfig.SUCCESS_CODE) {
						that.close()
						that.notes = null
						that.initArray()
					} else {
						
					}
				}
			})
		}
		
	},
	toMyfollow(){
		uni.navigateTo({
			url: '/pages/index/myFollow'
		})
	},
	selectTab(index){
		this.current = index
		this.page = 1
		this.list = []
		this.getPageList()
	},
	initArray(){
		this.page = 1
		this.list = []
		this.getPageList()
	},
	getPageList() {
		let that = this
		let url = ''
		this.current == 0? url='h5/getMyFollowPage':url='h5/getMyFansPage'
		if (that.loading) {
			return false
		}
		that.loading = true
		that.$httpRequest.get({
			that: that,
			url: url,
			params: {
				pageNo: that.page,
				pageSize: that.list_rows,
			},
			success: res => {
				that.loading = false
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					if (that.page === 1) {
						that.list = res.data.rows
					} else {
						that.list = that.list.concat(res.data.rows)
					}
					that.page++
				} else {
					
				}
			}
		})
	},
	//发表想法
	submit(){
		let that = this
		that.$httpRequest.request({
			that: that,
			url: 'h5/sendMessage',
			params: that.formData,
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.$toast.msg('留言成功', {
					    icon: 1
					})
					that.formData.content = ''
					that.close()
				}else{
					that.$toast.msg(res.message, {
					    icon: 1
					})
				}
			
			}
		})
	},
	toMyFans(){
		uni.navigateTo({
			url: '/pages/index/myFans'
		})
	},
	_previewImage(image) {
		var imgArr = [];
		imgArr.push(image);
		//预览图片
		uni.previewImage({
			urls: imgArr,
			current: imgArr[0]
		});
	},
	close(){
		this.$refs.sendPopup.close()
		this.$refs.notesPopup.close()
	},
	toComment(id){
		this.formData.toUserId = id
		this.$refs.sendPopup.open()
	}

}